package cn.wsalix.weixin.req.service.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.anlaser.service.impl.CommonServiceImpl;
import cn.anlaser.utils.SearchFilter;
import cn.anlaser.utils.SearchFilter.Operator;
import cn.wsalix.weixin.req.entity.TextReqMsg;
import cn.wsalix.weixin.req.form.TextReqMsgForm;
import cn.wsalix.weixin.req.repository.TextReqMsgRepository;
import cn.wsalix.weixin.req.service.TextReqMsgService;

@Service("textReqMsgService")
@Transactional(readOnly = true)
public class TextReqMsgServiceImpl extends
		CommonServiceImpl<TextReqMsgForm, TextReqMsgRepository, TextReqMsg>
		implements TextReqMsgService {

	@Autowired
	private TextReqMsgRepository textReqMsgRepository;

	@Override
	public TextReqMsgRepository getRepository() {
		return textReqMsgRepository;
	}

	@Override
	public String module() {
		return "wx/textmsg";
	}

	@Override
	public Map<String, SearchFilter> buildByForm(TextReqMsgForm form) {
		Map<String, SearchFilter> filters = buildFilter();

		if (form.getMsgType() != null && !form.getMsgType().equals("")) {
			filters.put("msgType", new SearchFilter("msgType", Operator.EQ,
					form.getMsgType()));
		}
		return filters;
	}

	@Override
	public Class<TextReqMsg> getEntityClazz() {
		return TextReqMsg.class;
	}

}
